package tmproject.hlhj.fhp.tmvote.customView

import android.app.Dialog
import android.content.Context
import android.os.BaseBundle
import android.os.Bundle
import com.bumptech.glide.Glide
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx.adapter.ObservableResponse
import kotlinx.android.synthetic.main.dialog_ewm.*
import rx.schedulers.Schedulers
import tmproject.hlhj.fhp.tmvote.R
import tmproject.hlhj.fhp.tmvote.beans.BaseBean
import tmproject.hlhj.fhp.tmvote.network.BaseObersever
import tmproject.hlhj.fhp.tmvote.network.JsonConvert
import tmproject.hlhj.fhp.tmvote.network.Urls
import tmproject.hlhj.fhp.tmvote.utils.ZxingUtils

/**
 * Created by Never Fear   on 2018\8\16 0016.
Never More....
 */
class EwmDialog(context: Context,private val imgUrl:String) :Dialog(context, R.style.MyDialog) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_ewm)

        OkGo.get<BaseBean>(Urls.Base_Url+Urls.Ewm)
                .params("pay_sn",imgUrl)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
                .subscribe(object :BaseObersever<Response<BaseBean>>(context){
                    override fun onRespSuccess(t: Response<BaseBean>) {
                        val baseBean = t.body()
                        val bitmap = ZxingUtils.createBitmap(baseBean.data.toString())
                        Glide.with(context)
                                .load(bitmap)
                                .into(ewmImg)
                    }
                })

    }
}